package com.slj.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.*;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.charset.Charset;
import java.util.List;

@Configuration //这是一个配置类
@ComponentScan("com.slj") //扫描交给spring管理的目录
@EnableWebMvc //启动springMvc的json功能
@PropertySource("classpath:database.properties")
@Import({JdbcConfig.class,MybatisConfig.class})
@EnableAspectJAutoProxy //开始SpringAOP的注解
@EnableTransactionManagement //开启事务
@MapperScan("com.slj.mapper") // 确保扫描Mapper接口
public class SpringMVCConfig implements WebMvcConfigurer {
    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        //处理返回值乱码
        StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
        converters.add(0,converter);

    }
}
